<?php

$username = "nguyenThiThanhThuong";
$password = "123456";
$submit = "Login";

$url ="http://localhost/test/curl/login/form.php";
$cookie_file = '/tmp/cookie.txt';
//echo '<pre>';print_r($_SERVER);echo '</pre>';
$nameField ="val[username]";
$passField ="val[password]";
$subField ="Login";

$page = curl_init($url);


curl_setopt($page , CURLOPT_POST, 1);
$postData = $nameField."=".$username."&".$passField."=".$password."&".$subField."=".$submit;
curl_setopt($page, CURLOPT_POSTFIELDS, $postData);
curl_setopt($page, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($page, CURLOPT_COOKIEJAR, $cookie_file);


$out = curl_exec($page);

//if(is_string($out)) {
//    echo $out;
//}

curl_setopt($page, CURLOPT_URL, 'http://localhost/test/curl/login/end.php');
$out2 = curl_exec($page);

print_r($out2);



//$login_email = 'abc';
//$login_pass = 'abc';
// 
//$ch = curl_init();
//curl_setopt($ch, CURLOPT_URL, 'http://www.facebook.com/login.php');
//curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_HEADER, 0);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/my_cookies.txt");
//curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/my_cookies.txt");
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
//curl_setopt($ch, CURLOPT_REFERER, "http://www.facebook.com");
//$page = curl_exec($ch);
//
//echo $page;